//----------------------------------------------------------
// ironcap.api
//----------------------------------------------------------
var ironcap        = {};
ironcap.indicator  = null;
ironcap.load_count = 0;
ironcap.api        = {};
ironcap.api.call   = function(url, params, callback){
	if(ironcap.load_count == 0) ironcap.indicator.show();
	ironcap.load_count += 1;
	
	$.ajax({ type        : 'POST', 
			 contentType : 'application/json; charset=utf-8', 
			 url         : url, 
			 data        : JSON.stringify(params), 
			 dataType    : 'json', 
			 success     : function (response) { 
				callback(response.result);
				
				ironcap.load_count -= 1;
				
				if(ironcap.load_count == 0) ironcap.indicator.fadeOut();				
			 }});			
}

//----------------------------------------------------------
// ironcap.ui
//----------------------------------------------------------
ironcap.ui  	   = {};
ironcap.ui.load    = function(selector, url, callback) {
	$(selector).load(url);
}

ironcap.ui.template = {};
ironcap.ui.template.initialize = function(selector, templateid, data) {
	var tmpl     = $('#' + templateid).html();
	var html     =  Mustache.to_html(tmpl, data);
	$(selector).html(html);
}

//----------------------------------------------------------
// ironcap.ui.editor
//----------------------------------------------------------			
ironcap.ui.editor = {};
ironcap.ui.editor.initialize = function(selector, language, value) {
	$(selector).html('<textarea></textarea>');
	var editor = CodeMirror.fromTextArea($(selector + ' textarea')[0], {
			mode: {
				name                   : language,
				version                : 2,
				singleLineStringErrors : false
			},
			lineNumbers   : true,
			indentUnit    : 4,
			tabMode       : "shift",
			matchBrackets : true
	});
	
	if(value) {
		editor.setValue(value);
	}
	return editor;				
}

//----------------------------------------------------------
// ironcap initialize
//----------------------------------------------------------
$(document).ready(function(){
	
	ironcap.indicator = $('#indicator');
	
	//ironcap.indicator.fadeOut();
	
});



